package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.IndustryCache;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserInfoHelper;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 10 产品线 USER_ITEM_INFOS.ORD10051 110WLW10109974有数据
 */
@UserAttrSupplier(attrField = LocalKeyConsts.PRODUCT_LINE_NEW)
@Service
public class ProductLineAnotherSupplier extends AbstractUserAttrSupplier {

    @Override
    public String getValue() {
        String lineVal = UserInfoHelper.getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.PRODUCT_LINE);
        if (KiteStringUtils.isEmpty(lineVal)) {
            lineVal = UserInfoHelper.getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.PRODUCT_LINE_NEW);
        }
        return lineVal;
    }

    @Override
    public String getValueDesc() {
        String lineVal = getValue();
        return Optional.ofNullable(IndustryCache.getIndustryName(lineVal)).orElse(lineVal);
    }
}
